#######################################################
#######################################################
#######################################################
### CREATED BY JONATHAN KING AND JESSICA SCHOENHERR ###
##### REPLICATION DATA FOR "A MATTER OF OPINION?" #####
#######################################################
#######################################################
#######################################################

library(ggplot2)

########################
### PREDICTED VALUES ###
########################

dpData <- read.csv("DeathPenaltyPredictionsPart2-20221024.csv")

dpData <- as.data.frame(dpData)

dpData$treatmentGroup <- as.factor(dpData$treatmentGroup)

deathPenaltyPredProb <- ggplot(dpData, aes(y = predValue, x = treatmentGroup, ymin = lowerValue, ymax = upperValue, color = female, fill = female)) +
	geom_bar(position = position_dodge(), stat = "identity") +
	facet_wrap(~partisanship) + 
	geom_errorbar(position = position_dodge(0.9), width=0.2, color = "grey25") + 
	theme_bw() +
	xlab("\nOpinion Writer Treatment Groups") +
	ylab("Predicted Value - Decision Thermometer\n") +
	ggtitle("Approval for Pro-Death Penalty Decision\nSecond Experiment") +
	theme(plot.title = element_text(hjust = 0.5)) +
	scale_x_discrete(labels = c("Liberal\nMale\nJustice", "Conservative\nMale\nJustice", "Liberal\nFemale\nJustice", "Conservative\nFemale\nJustice", "Control")) + 
	scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, 10)) +
	theme(legend.position = "bottom", legend.title = element_blank()) +
	scale_color_manual(values = c("grey75", "grey50"), labels = c("Women", "Men")) +
	scale_fill_manual(values = c("grey75", "grey50"), labels = c("Women", "Men")) +
	theme(strip.text.x = element_text(size = 12))
deathPenaltyPredProb

#################
### BY GENDER ###
#################

dpDyDx <- read.csv("~/Dropbox/JAS-JMK/Opinion\ Writer\ Paper/Data/DeathPenaltyDyDxGenderPart2-20221024.csv")

dpDyDx <- as.data.frame(dpDyDx)

dpDyDx$treatmentGroup <- as.factor(dpDyDx$treatmentGroup)

deathPenaltyChange <- ggplot(dpDyDx, aes(y = change, x = treatmentGroup, ymin = lowerCI, ymax = upperCI)) +
	geom_hline(aes(yintercept = 0), color = "grey75", size = 1.5) +
	geom_pointrange(fatten = 1, size = 1) +
	facet_wrap(~partisanship) +
	theme_bw() +
	ggtitle("Differences between Male and Female Participants, Approval for Pro-Death Penalty Decision\nSecond Experiment") +
	ylab("Difference in Feeling Thermometer (Female - Male)\n") +
	xlab("\nOpinion Writer Treatment Groups") +
	theme(plot.title = element_text(hjust = 0.5)) +
	scale_x_discrete(labels = c("Liberal\nMale\nJustice", "Conservative\nMale\nJustice", "Liberal\nFemale\nJustice", "Conservative\nFemale\nJustice", "Control")) +
	scale_y_continuous(limits = c(-45, 45), breaks = seq(-45, 45, 10)) +
	theme(strip.text.x = element_text(size = 12))
deathPenaltyChange

#######################
### BY PARTISANSHIP ###
#######################


dpDyDx2 <- read.csv("~/Dropbox/JAS-JMK/Opinion\ Writer\ Paper/Data/DeathPenaltyDyDxPartisanshipPart2-20221024.csv")

dpDyDx2 <- as.data.frame(dpDyDx2)

dpDyDx2$treatmentGroup <- as.factor(dpDyDx2$treatmentGroup)

deathPenaltyChange2 <- ggplot(dpDyDx2, aes(y = change, x = treatmentGroup, ymin = lowerCI, ymax = upperCI)) +
	geom_hline(aes(yintercept = 0), color = "grey75", size = 1.5) +
	geom_pointrange(fatten = 1, size = 1) +
	facet_wrap(~gender) +
	theme_bw() +
	ggtitle("Differences between Democrat and Republican Participants, Approval for Pro-Death Penalty Decision\nSecond Experiment") +
	ylab("Difference in Feeling Thermometer (Republican - Democrat)\n") +
	xlab("\nOpinion Writer Treatment Groups") +
	theme(plot.title = element_text(hjust = 0.5)) +
	scale_x_discrete(labels = c("Liberal\nMale\nJustice", "Conservative\nMale\nJustice", "Liberal\nFemale\nJustice", "Conservative\nFemale\nJustice", "Control")) +
	scale_y_continuous(limits = c(-45, 45), breaks = seq(-45, 45, 10)) +
	theme(strip.text.x = element_text(size = 12))
deathPenaltyChange2

